<?php
	if (!session_id()) session_start();
	if(!isset($_SESSION['user_id'])) {
		 header("Location: user_login");
		 exit;
	}
?>
<?php
	require_once('header.php');
	require_once('navbar.php');
	require_once('configure/db_fns.php');
	require_once('configure/parameter.php');
	require_once('paganation/page.class.php');
?>
<?php
	$conn = db_connect();
	$conn->query("set names utf8");
	$result = $conn->query("select * from ".$users_info." where user_id='".$_SESSION['user_id']."'");
	if($result) {
		$row = $result->fetch_assoc();
		$view_cars = $row['view_cars'];
	}
	
?>
<script>
	//删除浏览历史
	function cancel_view(bt,car_id) {
		var collect_type = 1;
		$.ajax({
			type:"POST",
			url:"configure/delete_browsecars.php",
			cache:false,
			data:{"car_id":car_id,
				  
			},
			success:function(data) {
				//失败
				if(data==0) {
					content+= '<p class="helpbuy-demand-success helpbuy-demand-wrong">删除失败！请刷新后重试~</p>';
					show_clue(content);
				}
				//未登录
				else if(data==2) {
					content+= '<p class="helpbuy-demand-success helpbuy-demand-wrong">未登录！请刷新后重试~</p>';
					show_clue(content);
				}
				//成功
				else if(data==1) {
					$(bt).parents("li").remove();
					}
					//若为空，则显示为空的代码
					
					if($(".tab_box-divb").find('li').length==0) {
						$(".tab_box").html('<div class="release-box-right-prompt">您还没有浏览过任何二手车<a href="buy?city=<?php echo $city;?>"> 快去看看！</a></div>');
					}
			},
	  	});
		 
	}
</script>
 <div class="usercenter-box">
            <div class="usercenter-box-left">
                <div class="usercenter-box-left-face">
                    <div class="usercenter-box-left-faceimg"><img src="<?php echo $row['img_src']==""?'images/askface.png':$row['img_src'];?>" /></div>
                    <div class="usercenter-box-left-font">chituzhishen@163.com</div>
                </div>
                
                <div class="usercenter-box-left-ul">
                    <ul>
                       <?php
					      require_once('usercenter_navbar.php');
					   ?>
                    </ul>

                </div>
            </div>
            
            <div class="usercenter-box-right" id="tab">
                 <ul class="tab_menu">
                    <li class="useselected useleft">浏览历史</li>
                    <!--<li>待付款</li>
                    <li>已付款</li>
                    <li>交易关闭</li>
                    <li>交易完成</li>-->
                </ul>


                <div class="tab_box">
                	
                    <div class="tab_box-divb">
                  		<?php
							if($view_cars=="") {
								echo '<div class="release-box-right-prompt">您还没有浏览过任何二手车<a href="buy?city='.$city.'"> 快去看看！</a></div>';
							}
							else {
								$result = $conn->query("select * from ".$car_dataset." where id in(".$view_cars.") order by field (id,".$view_cars.") desc");
								$num_result = $result->num_rows;
								$view_content = '<ul>';
								while($row = $result->fetch_assoc()) {
									if($row['img_src']=="") {
									  $img_src = "../cheyuzhou_bg/upload/lost.jpg";
								  	}
								  	else {
								  		$arr = explode(";",$row['img_src']);
								  		$img_src = $arr[0]; 
								  	}
									$view_content.='<a href="'.$SER_ADD.'/buycar_detail?id='.$row['id'].'"><li><img src="../cheyuzhou_bg/'.$img_src.'" /><span class="collect-name">'.$row['brand_name'].'</span><p class="collect-newp"><span>￥'.$row['current_price'].'万</span><span class="collect-new">新车价￥'.$row['new_price'].'万</span></p><p>上牌 '.$row['plate_date'].'｜ 里程 '.$row['driving_distance'].'万公里</p><div class="collect-button-cancel" onclick="cancel_view(this,\''.$row['id'].'\');return false"><i class="reddel"></i>&nbsp;&nbsp;&nbsp;&nbsp;删除</div></li></a>';
								}
								$view_content.= '</ul>';
								echo $view_content;
							}
					
						?>
                    </div>
                  <!--  <div class="hidea"></div>
                    	<div class="hidea"></div>
                        <div class="hidea"></div>
                        <div class="hidea"></div>
                     -->
                </div>
           </div>
           
       </div>
 

          
<!--底部-->
<?php
	require_once('footer.php');
?>